﻿using System;
using System.Collections.Generic;
using System.Text;
using DevExpress.Persistent.Base;
using DevExpress.Xpo;
using DevExpress.Persistent.BaseImpl;
using System.ComponentModel;
using DevExpress.ExpressApp.SystemModule;

namespace CRMSolution.Module
{
    [NavigationItem("销售")]
    [Custom("Caption", "销售机会")]
    [DefaultProperty("Title")]
    public class SalesChance : CommonInfo
    {
        public SalesChance(Session session) : base(session) { }

        private string _title;
        [Custom("Title", "机会名称")]
        public string Title
        {
            get
            {
                return _title;
            }
            set
            {
                SetPropertyValue<string>("Title", ref _title, value);
            }
        }
        private Customer _customer;
        [Custom("Caption", "客户")]
        public Customer Customer
        {
            get
            {
                return _customer;
            }
            set
            {
                SetPropertyValue<Customer>("Customer", ref _customer, value);
            }
        }
        private string _salesState;
        [Custom("Caption", "销售阶段")]
        public string SalesSate
        {
            get
            {
                return _salesState;
            }
            set
            {
                SetPropertyValue<string>("SalesSate", ref _salesState, value);
            }
        }
        private string _customersource;
        [Custom("Caption", "客户来源")]
        public string CustomerSource
        {
            get
            {
                return _customersource;
            }
            set
            {
                SetPropertyValue<string>("CustomerSource", ref _customersource, value);
            }
        }
        private DateTime _planFinishedDate;
        [Custom("Caption", "预计成交日期")]
        public DateTime PlanFinishedDate
        {
            get
            {
                return _planFinishedDate;
            }
            set
            {
                SetPropertyValue<DateTime>("PlanFinishedDate", ref _planFinishedDate, value);
            }
        }
        private int _possibility;
        [Custom("Caption", "可能性")]
        public int Possibility
        {
            get { return _possibility; }
            set
            {
                SetPropertyValue<int>("Possibility", ref _possibility, value);
            }
        }
        private string _suggest;
        [Custom("Caption", "建议")]
        [Size(1000)]
        public string Suggest
        {
            get
            {
                return _suggest;
            }
            set
            {
                SetPropertyValue<string>("Suggest", ref _suggest, value);
            }
        }
    }
    [NavigationItem("销售")]
    [Custom("Caption", "竞争对手")]
    [DefaultProperty("CompanyName")]
    public class Competitors : CommonInfo
    {
        public Competitors(Session session) : base(session) { }
        private string _companyname;
        [Custom("Caption", "公司名称")]
        public string CompanyName
        {
            get
            {
                return _companyname;
            }
            set
            {
                SetPropertyValue<string>("CompanyName", ref _companyname, value);
            }
        }
        private string _contactName;
        [Custom("Caption", "联系人")]
        public string ContactName
        {
            get
            {
                return _contactName;
            }
            set
            {
                SetPropertyValue<string>("ContactName", ref _contactName, value);
            }
        }
        private string _contactTelephone;
        [Custom("Caption", "联系电话")]
        public string ContactTelephone
        {
            get { return _contactTelephone; }
            set
            {
                SetPropertyValue<string>("ContactTelephone", ref _contactTelephone, value);
            }
        }

        private string _description;
        [Custom("Caption", "说明")]
        public string Description
        {
            get
            {
                return _description;
            }
            set
            {
                SetPropertyValue<string>("Description", ref _description, value);
            }
        }
    }

    [Custom("Caption", "单据中的产品详细信息")]
    public class OrderProductDetail : CommonInfo
    {
        public OrderProductDetail(Session session) : base(session) { }

        private AbsOrder _absorder;
        [Custom("Caption", "单据")]
        [Association("AbsOrder-ProductDetails")]
        public AbsOrder AbsOrder
        {
            get
            {
                return _absorder;
            }
            set
            {
                SetPropertyValue<AbsOrder>("AbsOrder", ref _absorder, value);
            }
        }

        private Product _product;
        [Custom("Caption", "产品")]
        public Product Product
        {
            get
            {
                return _product;
            }
            set
            {
                SetPropertyValue<Product>("Product", ref _product, value);
            }
        }
        private int _productCount;
        [Custom("Caption", "产品数量")]
        public int ProductCount
        {
            get
            {
                return _productCount;
            }
            set
            {
                SetPropertyValue<int>("ProductCount", ref _productCount, value);
            }
        }
        private decimal _currentPrice;
        [Custom("Caption", "当前价格")]
        public decimal CurrentPrice
        {
            get
            {
                return _currentPrice;
            }
            set
            {
                SetPropertyValue<decimal>("CurrentPrice", ref _currentPrice, value);
            }
        }
        private string _description;
        [Custom("Caption", "说明")]
        public string Description
        {
            get { return _description; }
            set
            {
                SetPropertyValue<string>("Description", ref _description, value);
            }
        }
    }

    [NavigationItem("销售")]
    [Custom("Caption", "报价单")]
    public class QuoteOrder : AbsOrder
    {
        public QuoteOrder(Session session) : base(session) { }

        protected override SeedType SeedType
        {
            get { return SeedType.QuoteOrder; }
        }
        private QuoteOrderState _quoteOrderState;
        [Custom("Caption", "报价单状态")]
        public QuoteOrderState QuteOrderState
        {
            get { return _quoteOrderState; }
            set
            {
                SetPropertyValue<QuoteOrderState>("QuteOrderState", ref _quoteOrderState, value);
            }
        }
        private string _title;
        [Custom("Caption", "报价单名称")]
        public string Title
        {
            get { return _title; }
            set
            {
                SetPropertyValue<string>("Title", ref _title, value);
            }
        }
   

        private DateTime _quotedate;
        [Custom("Caption", "报价日期")]
        public DateTime QuoteDate
        {
            get { return _quotedate; }
            set
            {
                SetPropertyValue<DateTime>("QuoteDate", ref _quotedate, value);
            }
        }

        [Custom("Caption", "附件")]
        [Association("QuoteOrder-QuoteOrderAttachment")]
        public XPCollection<QuoteOrderAttachment> Attachments
        {
            get
            {
                return GetCollection<QuoteOrderAttachment>("Attachments");
            }
        }
    }
    [Custom("Caption","报价单附件")]
    public class QuoteOrderAttachment : CommonInfo
    {
        public QuoteOrderAttachment(Session session)
            : base(session)
        {

        }
        private QuoteOrder _quoteOrder;
        [Custom("Caption", "报价单")]
        [Association("QuoteOrder-QuoteOrderAttachment")]
        public QuoteOrder QuoteOrder
        {
            get { return _quoteOrder; }
            set { SetPropertyValue<QuoteOrder>("QuoteOrder", ref _quoteOrder, value); }
        }


        private FileData _att;
        [Custom("Caption", "Attachment")]
        public FileData Attachment
        {
            get { return _att; }
            set { SetPropertyValue<FileData>("Attachment", ref _att, value); }
        }
    }

    [NavigationItem("销售")]
    [Custom("Caption", "合同订单")]
    [ListViewFilter("AllAgreementOrder","","所有合同",true,Index=0)]
    [ListViewFilter("CancelState","AgreementOrderState='0'","已取消",false)]
    [ListViewFilter("SendState", "AgreementOrderState='3'", "已发送", false)]
    public class AgreementOrder : AbsOrder
    {
        public AgreementOrder(Session session) : base(session) { }

        protected override SeedType SeedType
        {
            get { return SeedType.AgreementOrder; }
        }
        private AgreementOrderState _agreementOrderState;
        [Custom("Caption", "合同订单状态")]
        public AgreementOrderState AgreementOrderState
        {
            get { return _agreementOrderState; }
            set
            {
                SetPropertyValue<AgreementOrderState>("AgreementOrderState", ref _agreementOrderState, value);
            }
        }
        
        private DateTime _signDate;
        [Custom("Caption", "签约日期")]
        public DateTime SignDate
        {
            get { return _signDate; }
            set
            {
                SetPropertyValue<DateTime>("SignDate", ref _signDate, value);
            }
        }
        
        
    }
    [NavigationItem("销售")]
    [Custom("Caption", "发货单")]
    public class ShippingOrder : AbsOrder
    {
        public ShippingOrder(Session session) : base(session) { }
        protected override SeedType SeedType
        {
            get { return SeedType.ShippingOrder; }
        }
        private QuoteOrder _quoteOrder;
        [Custom("Caption", "合同订单")]
        public QuoteOrder QuoteOrder
        {
            get { return _quoteOrder; }
            set
            {
                SetPropertyValue<QuoteOrder>("QuoteOrder", ref _quoteOrder, value);
            }
        }
        private ShippingOrderState _shippingOrderState;
        [Custom("Caption", "发货单阶段")]
        public ShippingOrderState ShippingOrderState
        {
            get { return _shippingOrderState; }
            set
            {
                SetPropertyValue<ShippingOrderState>("ShippingOrderState", ref _shippingOrderState, value);
            }
        }

        private DateTime _invoiceDate;
        [Custom("Caption", "开票日期")]
        public DateTime InvoiceDate
        {
            get { return _invoiceDate; }
            set
            {
                SetPropertyValue<DateTime>("InvoiceDate", ref _invoiceDate, value);
            }
        }
      
    }
    [NavigationItem("销售")]
    [Custom("Caption", "退货单")]
    public class FailOrder : AbsOrder
    {
        public FailOrder(Session session) : base(session) { }
        protected override SeedType SeedType
        {
            get { return SeedType.FailOrder; }
        }
        
        private DateTime _failDate;
        [Custom("Caption", "退货时间")]
        public DateTime FailDate
        {
            get { return _failDate; }
            set
            {
                SetPropertyValue<DateTime>("FailDate", ref _failDate, value);
            }
        }
        private FailOrderState _failOrderState;
        [Custom("Caption", "退货状态")]
        public FailOrderState FailOrderState
        {
            get { return _failOrderState; }
            set
            {
                SetPropertyValue<FailOrderState>("FailOrderState", ref _failOrderState, value);
            }
        }
        private string _failReason;
        [Custom("Caption", "退货原因")]
        public string FailReason
        {
            get { return _failReason; }
            set
            {
                SetPropertyValue<string>("FailReason", ref _failReason, value);
            }
        }
        
    }
}
